package com.example.httpprocessor.http;
import android.app.Application;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;
import java.util.Map;

import javax.inject.Inject;

public class XUtilsProcessor implements IHttpProcessor{

    @Inject
    public XUtilsProcessor(Application app) {
        x.Ext.init(app);
    }

    @Override
    public void post(String url, Map<String, Object> params, HttpCallback callback) {

        RequestParams requestParams = new RequestParams(url);
        x.http().post(requestParams, new Callback.CacheCallback<String>() {
            @Override
            public boolean onCache(String result) {
                return false;
            }

            @Override
            public void onSuccess(String result) {
                 callback.onSuccess(result);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                 callback.onFailure("请求失败");
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });

    }
}
